/**
 * 运单管理 - 主界面
 */
Ext.define("PSI.Express.MainForm", {
	extend : "Ext.panel.Panel",
	border : 0,
	layout : "border",

	config : {
		pAdd : null,
		pEdit : null,
		pDelete : null,
		pTracing : null
	},

	/**
	 * 初始化组件
	 */
	initComponent : function() {
		var me = this;

		Ext.apply(me, {
					tbar : [{
								text : "下单",
								disabled : me.getPAdd() == "0",
								iconCls : "PSI-button-add",
								handler : me.onAddExpress,
								scope : me
							}, {
								text : "运单变更",
								iconCls : "PSI-button-edit",
								disabled : me.getPEdit() == "0",
								handler : me.onEditExpress,
								scope : me
							}, {
								text : "取消运单",
								disabled : me.getPDelete() == "0",
								iconCls : "PSI-button-delete",
								handler : me.onDeleteExpress,
								scope : me
							}, "-", {
								text : "运单进度跟踪",
								disabled : me.getPTracing() == "0",
								iconCls : "PSI-button-dataorg",
								handler : me.onTracing,
								scope : me
							}, "-", {
								text : "关闭",
								iconCls : "PSI-button-exit",
								handler : function() {
									location.replace(PSI.Const.BASE_URL);
								}
							}],
					items : [{
								region : "center",
								xtype : "panel",
								layout : "fit",
								border : 0,
								items : [me.getMainGrid()]
							}]
				});

		me.callParent(arguments);
	},

	/**
	 * 下单
	 */
	onAddExpress : function() {
		var me = this;
		var form = Ext.create("PSI.Express.AddForm", {
			parentForm: me
		});
		form.show();
	},

	/**
	 * 运单变更
	 */
	onEditExpress : function() {
	},

	/**
	 * 取消运单
	 */
	onDeleteWarehouse : function() {
	},

	getMainGrid : function() {
		var me = this;
		if (me.__mainGrid) {
			return me.__mainGrid;
		}

		var modelName = "PSIExpressBill";
		Ext.define(modelName, {
					extend : "Ext.data.Model",
					fields : ["id", "code", "name", "inited", "dataOrg"]
				});

		me.__mainGrid = Ext.create("Ext.grid.Panel", {
					border : 0,
					viewConfig : {
						enableTextSelection : true
					},
					columnLines : true,
					columns : [{
								xtype : "rownumberer"
							}, {
								header : "仓库编码",
								dataIndex : "code",
								menuDisabled : true,
								sortable : false,
								width : 60
							}, {
								header : "仓库名称",
								dataIndex : "name",
								menuDisabled : true,
								sortable : false,
								width : 200
							}, {
								header : "建账完毕",
								dataIndex : "inited",
								menuDisabled : true,
								sortable : false,
								width : 70,
								renderer : function(value) {
									return value == 1
											? "完毕"
											: "<span style='color:red'>未完</span>";
								}
							}, {
								header : "数据域",
								dataIndex : "dataOrg",
								menuDisabled : true,
								sortable : false
							}],
					store : Ext.create("Ext.data.Store", {
								model : modelName,
								autoLoad : false,
								data : []
							}),
					listeners : {
						itemdblclick : {
							fn : me.onEditWarehouse,
							scope : me
						}
					}
				});

		return me.__mainGrid;
	}
});